﻿@{
    ViewData["Title"] = "Home Page";
}
<div id="layout" class="easyui-layout" style="width:100%;height:100%">
    <div data-options="region:'north'" style="height:50px;"></div>
    <div data-options="region:'west',split:true,collapsible:true,title:'菜单'" style="width:240px;">
        <div id="menu" class="easyui-sidemenu" data-options="data:[],multiple:false" style="width:100%;padding:5px;">
        </div>
    </div>
    <div data-options="region:'center'">
        <div id="tt" class="easyui-tabs" data-options=""  style="width:100%;height:100%;">
            <div title="欢迎" style="padding:5px;">
                <div class="text-center">
                    <h1 class="display-4">Welcome</h1>
                    <p>Learn about <a href="https://docs.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
                </div>
            </div>
        </div>
    </div>
    <div data-options="region:'south'" style="height:50px;"></div>
</div>

<script type="text/javascript">
    $(function () {
        $.ajax({
            type: "GET",
            dataType: "json",
            url: "/Home/GetMenu",
            headers: { 'authorization': "Bearer " + localStorage.getItem('token') },
            success: function (data) {
                console.info(data);
                $("#menu").sidemenu({
                    data: data
                    , onSelect: function (node) {
                        console.info(node)
                        if (node.children == null || node.children.length > 0) {
                            open1(JSON.parse(node.attributes).url, node.text);
                        }
                    }
                });
            },
            error: function (e) {
                console.info(e);
            }
        });

        $('#tt').tabs({
            onLoad: function (panel) {
                var plugin = panel.panel('options').title;
                panel.find('textarea[name="code-' + plugin + '"]').each(function () {
                    var data = $(this).val();
                    data = data.replace(/(\r\n|\r|\n)/g, '\n');
                    if (data.indexOf('\t') == 0) {
                        data = data.replace(/^\t/, '');
                        data = data.replace(/\n\t/g, '\n');
                    }
                    data = data.replace(/\t/g, '    ');
                    var pre = $('<pre name="code" class="prettyprint linenums"></pre>').insertAfter(this);
                    pre.text(data);
                    $(this).remove();
                });
                prettyPrint();
            }
        });
        $('#layout').layout('panel', "west").panel({
            onResize: function (w, h) {
                $("#menu").sidemenu('resize', { width: w - 10, height: '100%' });
            }
        });

    });
    function open1(plugin, pluginName) {
        if ($('#tt').tabs('exists', pluginName)) {
            $('#tt').tabs('select', pluginName);
        } else {
            var iframe = '<iframe src="/' + plugin + '/Index" frameborder="0" style="border:0;width:100%;height:100%;"></iframe>';

            $('#tt').tabs('add', {
                title: pluginName,
                //href: plugin + '.html',
                content: iframe,
                closable: true,
                bodyCls: 'content-doc',
                /*extractor: function (data) {
                 data = $.fn.panel.defaults.extractor(data);
                 var tmp = $('<div></div>').html(data);
                 data = tmp.find('#content').html();
                 console.log(data);
                 tmp.remove();
                 return data;
                 }*/
            });
        }
    }
</script>